package controllers;
import java.util.ArrayList;
import javax.enterprise.context.RequestScoped;
import javax.inject.Named;
import webService.ServiceTest;

/**
 *
 * @author Rasztemberg
 */

@Named(value="splashDeveloperBean")
@RequestScoped
public class SplashDevelopers {
    
    
    public WebServiceResult getPartnerServices(String url){
        
        WebServiceResult wsr = new WebServiceResult();
        wsr.url = url;
        
        String result = ServiceTest.testUserRestService(url);
        
        if(result == null)
        {
            wsr.status = "ERROR";
            wsr.error = result;
            
        }else{
            wsr.status = "OK";
            wsr.JSON = result;
        }
       return wsr;
    }
    
    public ArrayList<WebServiceResult> loadPartnerWebServices(){
        
        ArrayList<WebServiceResult> webServiceResults = new ArrayList<WebServiceResult>();
        
        for(String url: loadUrls()){
            WebServiceResult wsr = getPartnerServices(url);
            webServiceResults.add(wsr);
        }
        return webServiceResults;
    }
    
    public ArrayList<String> loadUrls(){
        
        ArrayList<String> urls = new ArrayList<String>();
        urls.add("http://localhost:8080/ITFriendU/");
        //urls.add("https://173.203.78.105/ssase12/");
        urls.add("http://localhost:8080/ITFriendU/");
        urls.add("http://localhost:8080/ITFriendU/");
        urls.add("http://localhost:8080/ITFriendU/");
        urls.add("http://localhost:8080/ITFriendU/");
        urls.add("http://localhost:8080/ITFriendU/");
        urls.add("http://localhost:8080/ITFriendU/");
        urls.add("http://localhost:8080/ITFriendU/");
        urls.add("http://localhost:8080/ITFriendU/");
        urls.add("http://localhost:8080/ITFriendU/");
        
        return urls;
    }
    
    public class WebServiceResult{
        
        public String url; 
        public String status; 
        public String JSON; 
        public String error;

        public String getUrl() {
            return url;
        }

        public void setUrl(String url) {
            this.url = url;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getJSON() {
            return JSON;
        }

        public void setJSON(String JSON) {
            this.JSON = JSON;
        }

        public String getError() {
            return error;
        }

        public void setError(String error) {
            this.error = error;
        }
        
        
        
    }
}
